package com.turnengine.client.local.mobile.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Mobile.
 */
public class Mobile implements IMobile, Comparable<IMobile> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The player id. */
	private int playerId = -1;
	/** The origin id. */
	private int originId = -1;
	/** The destination id. */
	private int destinationId = -1;

	/**
	 * Creates a new Mobile.
	 */
	public Mobile() {
	}

	/**
	 * Creates a new Mobile.
	 * @param id the id
	 * @param name the name
	 * @param playerId the player id
	 * @param originId the origin id
	 * @param destinationId the destination id
	 */
	public Mobile(int id, String name, int playerId, int originId, int destinationId) {
		setId(id);
		setName(name);
		setPlayerId(playerId);
		setOriginId(originId);
		setDestinationId(destinationId);
	}

	/**
	 * Creates a new Mobile.
	 * @param mobile the mobile
	 */
	public Mobile(Mobile mobile) {
		setId(mobile.getId());
		setName(mobile.getName());
		setPlayerId(mobile.getPlayerId());
		setOriginId(mobile.getOriginId());
		setDestinationId(mobile.getDestinationId());
	}

	/**
	 * Creates a new Mobile.
	 * @param iMobile the i mobile
	 */
	public Mobile(IMobile iMobile) {
		setId(iMobile.getId());
		setName(iMobile.getName());
		setPlayerId(iMobile.getPlayerId());
		setOriginId(iMobile.getOriginId());
		setDestinationId(iMobile.getDestinationId());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the player id.
	 * @return the player id.
	 */
	public int getPlayerId() {
		return playerId;
	}

	/**
	 * Returns the origin id.
	 * @return the origin id.
	 */
	public int getOriginId() {
		return originId;
	}

	/**
	 * Returns the destination id.
	 * @return the destination id.
	 */
	public int getDestinationId() {
		return destinationId;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the player id.
	 * @param playerId the player id to set.
	 */
	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	/**
	 * Sets the origin id.
	 * @param originId the origin id to set.
	 */
	public void setOriginId(int originId) {
		this.originId = originId;
	}

	/**
	 * Sets the destination id.
	 * @param destinationId the destination id to set.
	 */
	public void setDestinationId(int destinationId) {
		this.destinationId = destinationId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(877, 37);
		hash.append(id);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Mobile) {
			Mobile compare = (Mobile) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IMobile compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("playerId", playerId);
		string.append("originId", originId);
		string.append("destinationId", destinationId);
		return string.toString();
	}
}
